-----------------
-- CONVERGENCE --
-----------------
local Locales = {
	["Terax Blightweaver"] = {
		[1] = "Terax Blightweaver",
		[2] = "Terax Brandweber",
		[3] = "Terax Tisserouille",
	},
	["Golgox the Lifecrusher"] = {
		[1] = "Golgox the Lifecrusher",
		[2] = "Golgox der Lebenszermalmer",
		[3] = "Golgox le Fossoyeur",
	},
	["Fleshmonger Vratorg"] = {
		[1] = "Fleshmonger Vratorg",
		[2] = "Fleischhändler Vratorg",
		[3] = "Vratorg le Cannibale",
	},
	["Noxmind the Insidious"] = {
		[1] = "Noxmind the Insidious",
		[2] = "Noxgeist der Hinterlistige",
		[3] = "Toxultime l'Insidieux",
	},
	["Ersoth Curseform"] = {
		[1] = "Ersoth Curseform",
		[2] = "Ersoth Fluchform",
		[3] = "Ersoth le Maudisseur",
	},
	["Teleport"] = { --74371
		[1] = "Teleport",
		[2] = "Teleport",
		[3] = "Se téléporter",
	},
	["Stitching Strain"] = { --57412
		[1] = "Stitching Strain",
		[2] = "Mit Transmutation anstecken",
		[3] = "Pression de suture",
	},
	["Demolish"] = { --61403
		[1] = "Demolish",
		[2] = "Demolieren",
		[3] = "Démolir",
	},
	["Scatter"] = { --56634
		[1] = "Scatter",
		[2] = "Streuung",
		[3] = "Disperser",
	},
	["Essence Rot"] = { --58423
		[1] = "Essence Rot",
		[2] = "Essenzfäulnis",
		[3] = "Pourriture d'essence",
	},
	["MIDDLE PHASE"] = {
		[1] = "MIDDLE PHASE",
		[2] = "Mittelphase",
		[3] = "PHASE CENTRE",
	},
	["INTERRUPT TERAX"] = {
		[1] = "INTERRUPT TERAX",
		[2] = "Terax unterbrechen!",
		[3] = "KICK TERAX",
	},
	["MID - TERAX"] = {
		[1] = "MID - TERAX",
		[2] = "Mitte - Terax",
		[3] = "CENTRE - TERAX",
	},
	["MID - GOLGOX"] = {
		[1] = "MID - GOLGOX",
		[2] = "Mitte - Golgox",
		[3] = "CENTRE - GOLGOX",
	},
	["MID - VRATORG"] = {
		[1] = "MID - VRATORG",
		[2] = "Mitte - Vratorg",
		[3] = "CENTRE - VRATORG",
	},
	["MID - NOXMIND"] = {
		[1] = "MID - NOXMIND",
		[2] = "Mitte - Noxmind",
		[3] = "CENTRE - TOXULTIME",
	},
	["MID - ERSOTH"] = {
		[1] = "MID - ERSOTH",
		[2] = "Mitte - Ersoth",
		[3] = "CENTRE - ERSOTH",
	},
	["Equalize"] = {
		[1] = "Equalize",
		[2] = "",
		[3] = "",
	},
	["Noxmind the Insidious prepares to equalize the Convergence!"] = {
		[1] = "Noxmind the Insidious prepares to equalize the Convergence!",
		[2] = "",
		[3] = "",
	},
}

local function GAConvergence(tUnits)
	local currTime = GameLib.GetGameTime()
	for unitid, unitdata in pairs(tUnits) do
		local unitname = unitdata.unit:GetName()
		if unitname == Raiderino.L["Terax Blightweaver"] then
			local castname = Raiderino:GetCast(unitid,unitdata.unit)
			if castname then
				if castname == Raiderino.L["Stitching Strain"] then
					if Raiderino:FeatureCheck("Terax Blightweaver","Stitching Strain") then
						local msg = {text = "Stitching Strain", maxtime = 60, icon = nil, destroyAtEnd = true}
						Raiderino.timers:AddTimer(msg)
						local msg = {text = "INTERRUPT TERAX", maxtime = 5, icon = nil, destroyAtEnd = true}
						Raiderino.notifications:AddTimer(msg)
					end
				elseif castname == Raiderino.L["Teleport"] then
					local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
					Raiderino.timers:AddTimer(msg)
					local msg = {text = "MID - TERAX", maxtime = 20, icon = nil, destroyAtEnd = true}
					Raiderino.notifications:AddTimer(msg)
				else
					Raiderino:UntimedCastAdd(unitname,castname)
				end
			end
		elseif unitname == Raiderino.L["Golgox the Lifecrusher"] then
			local castname = Raiderino:GetCast(unitid,unitdata.unit)
			if castname then
				if castname == Raiderino.L["Teleport"] then
					local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
					Raiderino.timers:AddTimer(msg)
					local msg = {text = "MID - GOLGOX", maxtime = 20, icon = nil, destroyAtEnd = true}
					Raiderino.notifications:AddTimer(msg)
				elseif castname == Raiderino.L["Demolish"] then
					if Raiderino:FeatureCheck("Golgox the Lifecrusher","Demolish") then
						local msg = {text = "Demolish", maxtime = 16, icon = nil, destroyAtEnd = true}
						Raiderino.timers:AddTimer(msg)
					end
				elseif castname == Raiderino.L["Scatter"] then
					if Raiderino:FeatureCheck("Golgox the Lifecrusher","Scatter") then
						local msg = {text = "Scatter", maxtime = 35, icon = nil, destroyAtEnd = true}
						Raiderino.timers:AddTimer(msg)
					end
				else
					Raiderino:UntimedCastAdd(unitname,castname)
				end
			end
		elseif unitname == Raiderino.L["Fleshmonger Vratorg"] then
			local castname = Raiderino:GetCast(unitid,unitdata.unit)
			if castname then
				if castname == Raiderino.L["Teleport"] then
					local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
					Raiderino.timers:AddTimer(msg)
					local msg = {text = "MID - VRATORG", maxtime = 20, icon = nil, destroyAtEnd = true}
					Raiderino.notifications:AddTimer(msg)
				else
					Raiderino:UntimedCastAdd(unitname,castname)
				end
			end
		elseif unitname == Raiderino.L["Noxmind the Insidious"] then
			local castname = Raiderino:GetCast(unitid,unitdata.unit)
			if castname then
				if castname == Raiderino.L["Teleport"] then
					local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
					Raiderino.timers:AddTimer(msg)
					local msg = {text = "MID - NOXMIND", maxtime = 20, icon = nil, destroyAtEnd = true}
					Raiderino.notifications:AddTimer(msg)
				elseif castname == Raiderino.L["Essence Rot"] then
					if Raiderino:FeatureCheck("Noxmind the Insidious","Essence Rot") then
						local msg = {text = "Essence Rot", maxtime = 20, icon = nil, destroyAtEnd = true}
						Raiderino.timers:AddTimer(msg)
					end
				else
					Raiderino:UntimedCastAdd(unitname,castname)
				end
			end
		elseif unitname == Raiderino.L["Ersoth Curseform"] then
			local castname = Raiderino:GetCast(unitid,unitdata.unit)
			if castname then
				if castname == Raiderino.L["Teleport"] then
					local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
					Raiderino.timers:AddTimer(msg)
					local msg = {text = "MID - ERSOTH", maxtime = 20, icon = nil, destroyAtEnd = true}
					Raiderino.notifications:AddTimer(msg)
				else
					Raiderino:UntimedCastAdd(unitname,castname)
				end
			end
		end
	end
end

local function StartTerax()
	if Raiderino:FeatureCheck("Terax Blightweaver","Stitching Strain") then
		local msg = {text = "Stitching Strain", maxtime = 18, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
	if not Raiderino.timers.content["MIDDLE PHASE"] then
		local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
end

local function PhaseTerax(phase)

end

local function StartGolgox()
	if Raiderino:FeatureCheck("Golgox the Lifecrusher","Demolish") then
		local msg = {text = "Demolish", maxtime = 16, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
	if Raiderino:FeatureCheck("Golgox the Lifecrusher","Scatter") then
		local msg = {text = "Scatter", maxtime = 32, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
	if not Raiderino.timers.content["MIDDLE PHASE"] then
		local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
end

local function PhaseGolgox(phase)

end

local function StartNoxmind()
	if Raiderino:FeatureCheck("Noxmind the Insidious","Essence Rot") then
		local msg = {text = "Essence Rot", maxtime = 20, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
	if not Raiderino.timers.content["MIDDLE PHASE"] then
		local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
	Raiderino:AddDatachronHandler(
		"Noxmind the Insidious prepares to equalize the Convergence!",
		function()
			local msg = {text = "Equalize", maxtime = 37, icon = nil, destroyAtEnd = true}
			Raiderino.notifications:AddTimer(msg)
		end
	)
end

local function PhaseNoxmind(phase)

end

local function StartErsoth()
	if not Raiderino.timers.content["MIDDLE PHASE"] then
		local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
end

local function PhaseErsoth(phase)

end

local function StartVratorg()
	if not Raiderino.timers.content["MIDDLE PHASE"] then
		local msg = {text = "MIDDLE PHASE", maxtime = 90, icon = nil, destroyAtEnd = true}
		Raiderino.timers:AddTimer(msg)
	end
end

local function PhaseVratorg(phase)

end
------------------
-- /CONVERGENCE --
------------------

if _G["RaiderinoLibs"] == nil then
	_G["RaiderinoLibs"] = { }
end
if _G["RaiderinoLibs"]["Encounters"] == nil then
	_G["RaiderinoLibs"]["Encounters"] = { }
end

local encounteroptions = {
	enabled = true,
	position = 8,
	zone = "Genetic Archives - Act 2",
	fBossFunction = GAConvergence,
	fPhaseFunction = PhaseTerax,
	fOnStartCombat = StartTerax,
	features = {
		["Stitching Strain"] = {
			displayname = "Stitching Strain",
			enabled = true
		},
	},
}

_G["RaiderinoLibs"]["Encounters"]["Terax Blightweaver"] = encounteroptions

local encounteroptions = {
	enabled = true,
	position = 9,
	zone = "Genetic Archives - Act 2",
	fBossFunction = GAConvergence,
	fPhaseFunction = PhaseGolgox,
	fOnStartCombat = StartGolgox,
	features = {
		["Demolish"] = {
			displayname = "Demolish",
			enabled = true
		},
		["Scatter"] = {
			displayname = "Scatter",
			enabled = true
		},
	},
}

_G["RaiderinoLibs"]["Encounters"]["Golgox the Lifecrusher"] = encounteroptions

local encounteroptions = {
	enabled = true,
	position = 10,
	zone = "Genetic Archives - Act 2",
	fBossFunction = GAConvergence,
	fPhaseFunction = PhaseVratorg,
	fOnStartCombat = StartVratorg,
	features = {},
}

_G["RaiderinoLibs"]["Encounters"]["Fleshmonger Vratorg"] = encounteroptions

local encounteroptions = {
	enabled = true,
	position = 11,
	zone = "Genetic Archives - Act 2",
	fBossFunction = GAConvergence,
	fPhaseFunction = PhaseNoxmind,
	fOnStartCombat = StartNoxmind,
	features = {
		["Essence Rot"] = {
			displayname = "Essence Rot",
			enabled = true
		},
	},
}

_G["RaiderinoLibs"]["Encounters"]["Noxmind the Insidious"] = encounteroptions

local encounteroptions = {
	enabled = true,
	position = 12,
	zone = "Genetic Archives - Act 2",
	fBossFunction = GAConvergence,
	fPhaseFunction = PhaseErsoth,
	fOnStartCombat = StartErsoth,
	features = {},
}

_G["RaiderinoLibs"]["Encounters"]["Ersoth Curseform"] = encounteroptions

if _G["RaiderinoLibs"]["Locales"] == nil then
	_G["RaiderinoLibs"]["Locales"] = { }
end
for locale, localedata in pairs(Locales) do
	if not RaiderinoLibs.Locales[locale] then
		RaiderinoLibs.Locales[locale] = {}
		for i,localestring in pairs(localedata) do
			RaiderinoLibs.Locales[locale][i] = localestring
		end
	end
end